package org.jeecg.modules.app.util.check;

import org.jeecg.common.util.oConvertUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @BelongsProject: jeecg-boot-parent 校验工具类
 * @BelongsPackage: org.jeecg.modules.app.util.check
 * @Author: mi
 * @CreateTime: 2024-07-12 17:49
 * @Description:
 */
public class CheckUtil {


    /**
     * 校验密码
     * @param password
     * @return
     */
    public static Integer checkPassword(String password){

        int numbers = 0;
        int words = 0;
        int space = 0;
        int other = 0;
        for(int i=0;i<password.length();i++){
            char c=password.charAt(i);
            if((c>='a' && c<='z')|| (c>='A' && c<='Z')){
                words++;
                continue;
            }
            if(c>='0' && c<='9' ){
                numbers++;
                continue;
            }
            if(c==' '){
                space++;
                continue;
            }
            else{
                other++;
                continue;
            }
        }
        if (space > 0){
            return 1;
        }
        int shu=words+numbers+other;
        if (shu<6 || shu >20){
            return 1;
        }
        return 0;
    }


    /**
     * 校验手机号
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        if (oConvertUtils.isEmpty(phone)){
            return false;
        }


        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(16[0-9])|(17[0,1,2,3,5,6,7,8])|(18[0-9])|(19[0-9]))\\d{8}$";
        if (phone.length() != 11) {
            return false;
        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phone);
            boolean isMatch = m.matches();
            if (!isMatch) {
                return false;
            }
            return true;
        }
    }






}
